package com.lzh.mybatisdemo.controller;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 分区名称
 */
public class CustomizeWriteHandler implements CellWriteHandler {

    @Override
    public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        //添加了新的内容
    }

    @Override
    public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        if (Boolean.FALSE.equals(isHead) && cell.getCellType() == CellType.NUMERIC) {
            System.out.println(cell.getNumericCellValue());
            cell.setCellValue(BigDecimal.valueOf(cell.getNumericCellValue()).setScale(5, RoundingMode.HALF_UP).stripTrailingZeros().doubleValue());
            System.out.println(cell.getNumericCellValue());
        }

    }
}
